Repository navigation
feat: update spending balance modal - #1373
Conversation
Shows a move as a Move to Spark transfer row, re-checks the Move to Spark sheet after a cold-start sheet closes, keeps move payment hashes across relaunches, and injects the quote services so makeQuote is tested.
Stops quoting after a waiting early claim, sets aside exit data Spark rejects so backups go on, keeps a retry in doubt held against an earlier attempt's late failure, and fails the Release key check on a blank keychain item.
…ock skew Keep each different rejected exit copy and keep the staged data when the remote copy is gone; count a Spark failure as an earlier attempt only past a 10 s clock margin; cache the move hashes Activity reads per row. Verified: swiftformat --lint on changed files; unit tests pending on m1a
…ackup Set aside the staged exit data itself when the remote backup no longer holds it, instead of a fresh download that may be another device's. Verified: swiftformat --lint on changed files; unit tests pending on m1a
Every rejected exit copy goes under SPARK_EXIT_REJECTED_ plus the first 16 hex digits of its SHA-256, so two devices setting different copies aside at once can't overwrite each other. Verified: swiftformat --lint on changed files; unit tests pending on m1a
Check whether a Spark failure belongs to an earlier attempt and end the hold under one lock, so a retry recorded in between keeps its hold. Verified: swiftformat --lint on the changed file; unit tests pending on m1a
Before a retried Spark send goes out, record Spark's ids of the invoice's earlier attempts from the listing the send already reads. A late failure ends the hold only when its payment id is not one of them. Without ids, a failure created before the send or within the clock margin after it keeps the hold, so an earlier attempt's failure can't free a duplicate payment. Verified: ChannelFreeRailTests, MoveToSparkQuoteTests and SparkExitBackupTests pass on an iPhone 17 Pro simulator; swiftformat lint clean.
A failure of an earlier attempt that arrives while a retry is in doubt leaves the send's activity pending. When the hold then ends at the invoice's expiry, write Spark's latest send of the invoice, or mark the stored pending send failed when Spark lists none. Spark syncs now also end holds whose invoice expired, so this no longer waits for a new send. Verified: ChannelFreeRail, MoveToSpark activity, late outcome and quote, SparkExitBackup, SparkLightningSend, SparkPaymentSafety, SparkRelaunchActivity and SparkTransferActivity tests pass on an iPhone 17 Pro simulator; swiftformat lint clean.
A hold that ends at the invoice's expiry keeps its hash in a persisted list until its activity is saved, so a failed Spark listing or write is retried on the next Spark sync. Failing a stored pending send now reads, checks and writes the row in one core-queue operation, so a change saved in between isn't overwritten. Verified: ChannelFreeRail, MoveToSpark activity, late outcome and quote, SparkExitBackup, SparkLightningSend, SparkPaymentSafety, SparkRelaunchActivity and SparkTransferActivity tests pass on an iPhone 17 Pro simulator; swiftformat lint clean.
A waiting early claim left the first quote's fee as the deposit's cap, so Spark would not claim a later offer the user's approved fee still covers. The claim now caps at the approved fee. After a waiting claim the poll still sends no new quote; an offer above the approved fee ends as Unavailable and is claimed at maturity. Verified: SparkTransferFlow, SparkClaimOffer, SparkClaimFee, SparkFundingRecovery and ChannelFreeRail tests pass on an iPhone 17 Pro simulator; swiftformat lint clean.
When Spark rejects staged exit data and the remote backup now holds another device's exit data, set the staged copy aside and restore the remote one instead of uploading over it. After setting an unreadable backup aside, read the remote again and keep the restore pending if it changed meanwhile. A Spark send in doubt saved before this version, with no start time or attempt ids, stays held against any failure until its invoice expires. Verified: ChannelFreeRail, SparkExitBackup, SparkExit, SparkRelaunchActivity, SparkPaymentSafety, SparkLightningSend and MoveToSparkQuote tests pass on an iPhone 17 Pro simulator; swiftformat lint clean.
Keep Spark's ids of a retry's earlier attempts after Spark takes the retry, until it settles, so an earlier attempt's late failure neither ends its hold nor fails its pending Activity row. Note the restore of another device's exit backup before the staged copy is dropped, so a stop in between still restores it, and count a staged exit file that can't be read as pending rather than absent. Verified: ChannelFreeRail, SparkExitBackup, SparkExit, SparkRelaunchActivity, SparkPaymentSafety, SparkLightningSend, MoveToSparkQuote and SparkTransferFlow tests pass on an iPhone 17 Pro simulator; swiftformat lint clean.
Spending and Lightning Connections offered Move to Spark only while the channels had something to move, so a move in flight that used up their balance hid its own screen. They now also offer it while a move is kept for its result. Verified: MoveToSparkLateOutcome, MoveToSparkQuote, MoveToSparkActivity and MoveToSparkMath tests pass on an iPhone 17 Pro simulator; swiftformat lint clean.
Once Spark took a retry, its listing can still show only the earlier attempts' failures. Those failures now read pending while the invoice is unexpired and no other attempt is listed, so the node never pays an invoice the retry may still pay. Verified: ChannelFreeRailTests, SparkTransferFlowTests, SparkExitBackupTests and MoveToSparkLateOutcomeTests pass on an iPhone 17 Pro simulator
The restore only stages the exit data; Spark imports it once connected and may still reject it, so the log no longer calls it a success. Verified: log wording only; SparkExitBackupTests pass on an iPhone 17 Pro simulator
Takes master's v64 Spark copy for strings both sides changed and keeps this PR's translations of the keys master left alone, dropping keys the merged English file no longer has. The move to Spark journey keeps master's connections check and this PR's Activity row step. Verified: node scripts/validate-translations.js passes; the unit suite (unit-tests.yml selection) passes on an iPhone 17 Pro simulator
Once Spark took a retry, the launch's activity sync released its hold when Spark's list still showed only the earlier failed attempt. That dropped the stored expiry the duplicate check reads, so the node could pay the unexpired invoice while the retry may still settle. The startup release now skips failures of the attempts listed before the send Spark took, and releases the hold once Spark lists the retry itself failed. Verified: ChannelFreeRailTests, SparkPaymentSafetyTests, MoveToSparkQuoteTests and SparkExitBackupTests on an iOS simulator
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Critical impact] The PR appears safe to merge based on the code reviewed. SummaryReplaces the Move to Spark screens with an Update Spending Balance modal and lets Lightning payments combine channel and Spark funds after showing the update fee.
No actionable issues found. Tests were not run in this Linux environment. ovitrif explicitly leaves app termination between move settlement and channel closure out of scope; those channels remain available for manual closure. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Review Lightning payment] --> B{Needs combined funds?}
B -- No --> G[Send payment]
B -- Yes --> C[Show update fee]
C --> D[Swipe and refresh quote]
D --> E{New or higher update fee?}
E -- Yes --> C
E -- No --> F[Check allowance and coverage]
F --> H[Move channel funds to Spark]
H --> I[Close emptied channels]
H --> J[Wait for Spark balance]
J --> G
Reviews (1) · Last reviewed commit: "fix: keep the modal artwork 32 above its..." · Reviewed by Greptile |
App Status's Spark row opened the Spark connection detail only while its status read ready, so offline, with Spark's state already read, the detail could only be reached from Lightning Connections. The row now opens it once Spark has read its state, as on Android. Verified: AppStatusHelperTests and AppStatusExitTests on an iOS simulator
Replaces the Move to Spark screens with the Update Spending Balance modal: the live routing fee as "Update fee", Later and Update, then Spending Balance Updated with OK. The one-time timed sheet and the Move To Spark buttons on Spending and Lightning Connections open it. States without frames (in flight, partly moved, too large, failed) keep their behaviour inside the modal; their dismiss buttons share the UpdateSpendingBalanceDismiss id. The modal resets the move manager when it closes. Verified: swiftformat --lint on the changed Swift files
Once a move settles, on its first outcome or a late success, every channel it emptied is closed cooperatively with the usual transfer row; a failed close leaves the channel for a manual close. Channels that could send less than the move minimum before it are left alone. This replaces the single-channel Close button after a move. Verified: swiftformat --lint on the changed Swift files
A Lightning payment that only the channels and Spark together can cover runs with one swipe: confirm adds an "Update fee" row and opens its details, the swipe waits for the quote, moves the channel balance to Spark, then pays from Spark. The update fee guard charges nothing the user did not see: the update is quoted again at the swipe and right before the move, and a fee that rose, or none shown, returns to confirm with the new fee and moves nothing. Before moving, the quote and Spark's balance must cover the payment and Spark's fee for it. A request refused by its allowance check moves nothing, and any failed update releases the request. A payment failing after the move leaves the funds in Spark with the usual payment error. An LNURL-pay that needs the update shows its fee before the first swipe. QuickPay never sends such a payment, and Paykit routes are quoted only with what one rail can pay. Verified: swiftformat --lint on the changed Swift files
Send confirm no longer shows the Route row for a Paykit payment over Spark. The Pubky Swaps route row keeps it, so wallet__send_swap_route stays, as on Android. Verified: swiftformat --lint on the changed Swift files
pwltr
left a comment
There was a problem hiding this comment.
Reviewed 0d78546 against 1ef7403. The combined-balance send can start a paid Spark migration before it finishes checking whether the recipient payment can proceed.
Low: Check the effective Paykit deadline again at migration submission in SendConfirmationView.swift:2019 and LnurlPayConfirm.swift:385. A time-limited request can pass authorization and expire during migration preparation. The wallet can then pay the update fee and close an emptied channel while the recipient send is refused.
Low candidate: A still-valid invoice with a paid or pending attempt can reach migration before the existing duplicate check at SendConfirmationView.swift:2019 and LightningService.swift:1088. If Spark can price that repeat and the changed balances now need both rails, another swipe can move funds and trigger a close before send returns the earlier outcome.
Low candidate: MoveToSparkManager.swift:664 can accept a Spark quote that fits the projected balance but exceeds the cap applied at SparkManager.swift:652. A supported provider returning an above-cap quote both times would allow the paid move before the recipient send is refused.
Low: In the debug-regtest Pubky swap flow, SendAmountView.swift:114 offers the combined balance while SendAmountView.swift:449 enforces the one-rail cap. The maximum-fill shortcut can enable Continue with an amount that Continue immediately rejects. Apply the swap cap to the displayed and selectable amount.
Low candidate: ReceiveQr.swift:115 and ReceiveQr.swift:480 can use an expired cached Lightning invoice while Spark is unavailable and the channels have no inbound capacity. If Spending is selected before refresh suppresses the QR, it can display an unpayable invoice.
Low: MoveToSparkUpdateTests.swift:61 and MoveToSparkUpdateTests.swift:74 repeat the 50,000-sat and 31,999-sat assertions at lines 40–44 using the same fixtures. The contact routing and exact-capacity assertions provide distinct coverage.
Review details
Quick review
Model: Claude Opus 5.5
Reasoning effort: high
General review
Model: GPT-6.2 Sol
Reasoning effort: high
Combined review
Model: GPT-6.2 Sol
Reasoning effort: high
The update before a combined-balance send now moves nothing for an expired Paykit request, a repeat of a paid or pending invoice, or a Spark fee above the send's limit. A swap offers only what one rail sends, and Spending receive waits for a fresh invoice when none can be created. Verified: MoveToSpark, Lnurl pay, send confirmation, channel-free rail, Spark transfer, WalletViewModel send and QuickPay unit tests on the simulator
|
@pwltr all six are addressed in 465950f:
Both confirm screens now pass the request's submission deadline to the update, which checks it right before the move is paid. An expired request moves nothing, and its own error reaches the screen.
The update now runs the same earlier-attempt check
The coverage check now refuses a Spark fee above the limit the send applies (1% + 50 sats), so no paid move goes ahead for a send that would then be refused.
With a Pubky swap route set, the amount screen offers only what one rail sends, which is what Continue checks.
Spending now shows the refresh state instead of a cached QR while no invoice can be created.
Removed both repeats, keeping the contact routing and exact-capacity checks. |
pwltr
left a comment
There was a problem hiding this comment.
Reviewed 465950f against 1ef7403.
Both confirmation screens re-read mutable payment state after awaiting the fresh Spending update quote. Bind the swipe to the active confirmation, route, funding source and amount, then verify that context before continuing.
Medium: For a unified invoice that needs a Spending update and can also be paid from Savings, tapping FROM while the quote loads can switch the old swipe to Savings. If Savings preparation finishes before the quote returns, the swipe can pick up the newly calculated mining fee and submit the on-chain payment without a second swipe. Bitkit/Views/Wallets/Send/SendConfirmationView.swift:1152, Bitkit/Views/Wallets/Send/SendConfirmationView.swift:2079.
Medium: For a variable-amount LNURL payment that needs the update, going Back and continuing with a different in-range amount while the quote loads can cause the old swipe to request and pay an invoice for the edited amount. The callback validates the amount it was asked for, so it cannot catch the change. Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift:261, Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift:322, Bitkit/Views/Wallets/Send/LnurlPayAmount.swift:126.
Low: A split-balance Paykit request that expires during the payment-list read or move queue wait can still incur the update fee before the recipient payment is refused. Pass the effective deadline to the existing LDK submission hook for the migration as well. Bitkit/Managers/MoveToSparkManager.swift:673, Bitkit/ViewModels/WalletViewModel.swift:1251.
Low: If a first LNURL subscription payment needs an update only after liquidity changes during its callback, the late-fee refusal opens the failure screen. Return it to manual confirmation with the new fee, as the BOLT11 path does. Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift:227, Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift:450.
Low: testAnUpdateThatFallsShortMovesNothing repeats the 49,875/49,876 sat boundary through checkCoverage. It would still pass if the move dispatched before the guard. Extend the existing test to observe dispatch or keep the distinct estimator-failure case under a name that describes the coverage check. BitkitTests/MoveToSparkUpdateTests.swift:110.
Review details
Quick review
Model: Claude Opus 5.5
Reasoning effort: high
General review
Model: GPT-6.2 Sol
Reasoning effort: high
Combined review
Model: GPT-6.2 Sol
Reasoning effort: high
A swipe that needs the spending update stops, moving and sending nothing, when its source, route, invoice or amount changed while the update was quoted. The Paykit deadline is checked again when the update payment is submitted, and a first LNURL subscription payment stopped by a late update fee returns to manual confirmation. Verified: MoveToSpark, Lnurl pay, send confirmation, channel-free rail, Spark transfer, WalletViewModel send and QuickPay unit tests on the simulator
|
@pwltr all five are addressed in aa83108:
Each swipe that needs the update now records what it pays when it starts. After the update quote returns, it checks that record again, and stops with nothing moved or sent if anything changed.
On Confirm, the swipe records the source, invoice or address, amount, and whether a service or swap route is set. Switching to Savings mid-quote stops the old swipe instead of submitting on-chain.
LNURL Confirm records the LNURL and amount, and checks them after the quote and again right before requesting the invoice. An edited amount stops the old swipe.
The update payment now passes the deadline check to LDK's
An automatic first subscription payment stopped by a late update fee now goes back to manual confirmation with the new fee, as the BOLT11 path does.
Renamed it to |
1ef7403 to
41ed0d3
Compare
…t/update-spending-balance-modal # Conflicts: # Bitkit/Managers/MoveToSparkManager.swift # Bitkit/Resources/Localization/ar.lproj/Localizable.strings # Bitkit/Resources/Localization/ca.lproj/Localizable.strings # Bitkit/Resources/Localization/cs.lproj/Localizable.strings # Bitkit/Resources/Localization/de.lproj/Localizable.strings # Bitkit/Resources/Localization/el.lproj/Localizable.strings # Bitkit/Resources/Localization/es-419.lproj/Localizable.strings # Bitkit/Resources/Localization/es.lproj/Localizable.strings # Bitkit/Resources/Localization/fr.lproj/Localizable.strings # Bitkit/Resources/Localization/it.lproj/Localizable.strings # Bitkit/Resources/Localization/nl.lproj/Localizable.strings # Bitkit/Resources/Localization/pl.lproj/Localizable.strings # Bitkit/Resources/Localization/pt-BR.lproj/Localizable.strings # Bitkit/Resources/Localization/pt.lproj/Localizable.strings # Bitkit/Resources/Localization/ru.lproj/Localizable.strings # Bitkit/Services/LightningService.swift # BitkitTests/MoveToSparkQuoteTests.swift # journeys/transfer/move-to-spark.xml
…t/update-spending-balance-modal
pwltr
left a comment
There was a problem hiding this comment.
Reviewed 62c1e9e against befad53.
Low: The merge dropped lightning__spark_exit__note_notifications_button from 13 locale bundles. When a Spark Exit is active and notification permission is denied, the button at Bitkit/Views/Settings/Advanced/SparkExitViews.swift:968 falls back to English and shows “Turn on notifications.” Restore the entries from befad53 in Bitkit/Resources/Localization/*/Localizable.strings for ar, ca, cs, de, el, es-419, es, fr, it, pl, pt-BR, pt, and ru.
Review details
Quick review
Model: Claude Opus 5.5
Reasoning effort: high
General review
Model: GPT-6.2 Sol
Reasoning effort: high
Combined review
Model: GPT-6.2 Sol
Reasoning effort: high
…the screen The spark exit notifications button string is back in 13 locales, lost with the duplicate keys. A swipe whose payment changed while the update was quoted no longer opens the failure screen or sets its quote on the new payment, and Receive leaves Auto or Spending once they hide. Verified: MoveToSpark, Lnurl pay, send confirmation, channel-free rail, Spark transfer, WalletViewModel send and receive tabs unit tests on the simulator; validate-translations
Going Back, closing the sheet or editing the payment while the spending balance update is quoted no longer shows its failure or continues the payment, and a changed payment after warnings or PIN is not sent. Verified: swiftformat --lint; targeted BitkitTests on simulator
The Auto and Spending fallback also runs when the screen opens with Lightning receive already hidden. Tests cover the fallback and the update swipe bindings. Verified: swiftformat --lint; targeted BitkitTests on simulator
The update swipe compares the invoice's own amount, so filling the send amount in from the invoice after PIN no longer stops an unchanged payment. Verified: swiftformat --lint; targeted BitkitTests on simulator
{"kind":"bitkit-retarget-execution-v1","repository":"synonymdev/bitkit-ios","pr":1373,"generation":"45436892534-1","sourceSha":"737b2f946459ed6bb8ab3ca718b4bbd9e1c9e8e8","sourceRef":"master","owner":"github-actions[bot]"}
|
@pwltr Restored The same push also:
|
pwltr
left a comment
There was a problem hiding this comment.
Reviewed da2636a against 737b2f9.
Medium candidate: The final Spending update quote can outlive the confirmation that authorized it. When a payment needs both the channel and Spark balances, dismissing BOLT11 Confirm or tapping Back from variable-amount LNURL Confirm while the final quote is pending can still let Bitkit/Managers/MoveToSparkManager.swift:639 proceed to the channel move. If it settles and Spark has sufficient balance, Bitkit/Views/Wallets/Send/SendConfirmationView.swift:2033 can continue with the captured BOLT11 and Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift:406 can continue with the invoice for the old amount even after the payer returns to Amount. The source shows the path to submission. Whether the update fee or recipient payment settles after leaving Confirm remains unverified. Carry the confirmation identity through the final quote and check it immediately before submitting the move.
Review details
Quick review
Model: Claude Opus 5.5
Reasoning effort: high
General review
Model: GPT-6.2 Sol
Reasoning effort: high
Combined review
Model: GPT-6.2 Sol
Reasoning effort: high
|
@pwltr Thanks. That final quote runs after the swipe has passed every check, inside the payment the swipe sent: the same invoice, the same amount, and a fee no higher than the one shown, or it stops at |
|
Merging: approved at da2636a and every check is green. The e2e passed once its bitkit-e2e-tests branch was fast-forwarded to |
Closes #1374
Stacked on #1355
Twin: synonymdev/bitkit-android#1967
Description
TransferViewModel.closeChannels.Out of Scope
DisplayText,BodyMText: the headline and body line heights are the shared components' (about 2 pt under the frame's 44 and 22).Design
Figma page "Bitkit - Progress v64" in the Bitkit Wallet file:
Preview
Figma frame on the left, the app on the right, on
42a656e8f.Screens without a v64 frame
Recordings at 2x: J1 on
42a656e8f, J2 onf2b60fc6c, the others on1ca4159a7.pr4-j12x.mp4
pr4-j22x.mp4
pr4-j32x.mp4
pr4-j42x.mp4
pr4-j52x.mp4
Figma notes
Every note above the v64 frames for these flows, with what this PR does about it.
Modal Update Spending balance (Spark)
Modal Update Spending (Spark) done
Changelog v64
QA Notes
Setup
docs/spark-regtest.md), so the wallet holds an LDK channel to the stack's SSP Lightning node on the same chain as Spark.SPARK_LOCAL_CONFIG_B64from the docs) as the Spark SDK config with fee ladders off, Electrum on the stack, and the stack's chain API as Spark's chain service. This branch has no build setting for a local Spark, so this is a local patch toEnv.swiftandSparkManager.swift, not part of this PR.regtest/wallet0/sparkdirectory with a file), restored after.Journeys
move-to-spark.xml— Update modal with its fee, Later, Update, Updated modal, emptied channel closed — passed on42a656e8fupdate-spending-balance-payment.xml— a payment only channels and Spark together cover: "Update fee" row, no Route row, one swipe — passed onf2b60fc6ctransfer-unavailable-sheet.xml— with Spark down, the funding options and Receive without Lightning tabs — passed on1ca4159a7usdt-receive-swipe-tabs.xml— tabs without the CJIT card — passed on1ca4159a7receive-tabs-wraparound.xml— passed on1ca4159a7, step 10 includedpaykit-spark-route.xml(Route row removed) — not run: needs a paykit stack with a Pubky profileAutomated Checks
MoveToSparkUpdateTests.swift— update-fee guard, coverage before moving, closing only the channels a move emptied, the swipe waiting for the newest quoteMoveToSparkMathTests.swift,MoveToSparkQuoteTests.swift,MoveToSparkLateOutcomeTests.swift— when a payment needs the update, swap routes and Spark legs never doLnurlPayConfirmTests.swift— an automatic payment needing the update waits for a swipe; a refused fee restores only the current sendQuickPayPaymentCoordinatorTests.swiftcase — a payment that needs the update falls back to ConfirmReceiveTabsTests.swift— without Lightning receive the Spending and Auto tabs hideReceiveLiquidityDecisionTests.swift,TabBarReceiveTests.swiftwith the CJIT flowEvidence
On an iPhone 17 Pro simulator (regtest) with the local Spark stack:
1ca4159a7and42a656e8fonly the modal's artwork placement and fix: spark follow-ups #1355's base changes landed; the send, retry and Move to Spark test classes pass on42a656e8f.Gaps
Models used
Claude Opus 5.5(reasoning:medium)Claude Opus 5.5(reasoning:medium),Claude Sonnet 5.5(reasoning:high)Claude Opus 5.5(reasoning:medium)